package org.example.design.redis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;

public class redisDemo {
    public static void main(String[] args) {
    }
    //测试set和get
    private static void testGetSet(Jedis jedis){
        jedis.set("key1","value1");
        System.out.println(jedis.get("key1"));
    }
    //测试exists和del
    private static void testExistsAndDel(Jedis jedis){
        System.out.println(jedis.exists("key1"));
        System.out.println(jedis.exists("key2"));

        System.out.println(jedis.del("key1"));
        System.out.println(jedis.exists("key1"));
    }
    //测试expire和ttl
    private static void testExpireAndTTL(Jedis jedis){
        jedis.setex("key1",60,"value1");
        long ttl=jedis.ttl("key1");
        System.out.println(ttl);
    }
    //测试type
    private static void testType(Jedis jedis){
        System.out.println(jedis.type("key1"));
    }
    //测试字符串mget和mset
    private static void testMSetAndMGet(Jedis jedis){
        jedis.mset("key1","value1","key2","value2");
        List<String> list = jedis.mget("key1", "key2");
        System.out.println(list);
    }
    //测试字符串append
    private static void testAppend(Jedis jedis){
        System.out.println(jedis.get("key1"));
        jedis.append("key1","aaa");
        System.out.println(jedis.get("key1"));
    }
    //测试字符串getrange和setrange
    private static void testGetRangeAndSetRange(Jedis jedis){
        System.out.println(jedis.getrange("key1",1,4));
        jedis.setrange("key1",0,"zyx");
        System.out.println(jedis.get("key1"));
    }
    //测试字符串setnx,仅在键不存在时设置
    private static void testSetnx(Jedis jedis){
        long n=jedis.setnx("key1","value2");
        System.out.println(n);
    }
}
